<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('方案产品指定')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12">
      <form id="assign-micro-form">
        <input type="hidden" id="planId" name="planId" th:value="${planId}">
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="selectMicro()" shiro:hasPermission="sewage:sewagePlan:add">
        <i class="fa fa-plus"></i> 添加产品
      </a>
      <a class="btn btn-danger btn-del disabled" onclick="cancelAssignMicroAll()" shiro:hasPermission="sewage:sewagePlan:remove">
        <i class="fa fa-remove"></i> 批量取消指定
      </a>
      <a class="btn btn-warning" onclick="closeItem()">
        <i class="fa fa-reply-all"></i> 关闭
      </a>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var removeFlag = [[${@permission.hasPermi('sewage:sewagePlan:remove')}]];
  var datas = [[${@dict.getType('micro_unit_type')}]];
  var mpdatas = [[${@dict.getType('micro_pharm_type')}]];
  var prefix = ctx + "sewage/sewagePlan";

  $(function() {
    var options = {
      url: prefix + "/microList",
      queryParams: queryParams,
      showSearch: false,
      modalName: "菌剂",
      columns: [{
        checkbox: true
      },
      {
        field: 'microbialId',
        title: '菌剂ID',
        visible: false,
      },
      {
        field: 'microbialType',
        title: '菌剂类型',
        formatter: function(value, row, index) {
          return $.table.selectDictLabel(mpdatas, value);
        }
      },
      {
        field: 'microbialName',
        title: '菌剂名称',
      },
      {
        field: 'microbialLogoUrl',
        title: '产品图片',
        formatter: function(value, row, index) {
          return $.table.imageView(value, '/abvfile/micro');
        }
      },
      {
        field: 'microbialSpec',
        title: '产品规格',
      },
      {
        field: 'microbialUnit',
        title: '产品单位',
        formatter: function(value, row, index) {
          return $.table.selectDictLabel(datas, value);
        }
      },
      {
        field: 'microbialPrice',
        title: '菌剂价格(元)'
      },
      {
        title: '操作',
        align: 'center',
        formatter: function(value, row, index) {
          var actions = [];
          actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAssignMicro(\'' + row.microbialId + '\')"><i class="fa fa-remove"></i>取消分配</a> ');
          return actions.join('');
        }
      }]
    };
    $.table.init(options);
  });

  function queryParams(params) {
    var search = $.table.queryParams(params);
    search.planId = $("#planId").val();
    return search;
  }

  function selectMicro() {
    var url = prefix + '/selectMicro/' + $("#planId").val();
    $.modal.open("选择菌剂", url);
  }

  function cancelAssignMicroAll() {
    var rows = $.table.selectFirstColumns();
    if (rows.length == 0) {
      $.modal.alertWarning("请至少选择一条记录");
      return;
    }
    $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
      var data = { "planId": $("#planId").val(), "microbialIds": rows.join() };
      $.operate.submit(prefix + "/microCancelAll", "post", "json", data);
    });
  }

  function cancelAssignMicro(microbialId) {
    $.modal.confirm("确认要取消该解决方案产品吗？", function() {
      $.operate.post(prefix + "/microCancel", { "planId": $("#planId").val(), "microbialId": microbialId });
    });
  }
</script>
</body>
</html>